<!-- 新增/修改弹框 -->
<template>
  <!-- 新增/修改弹窗 -->
  <el-dialog
    v-model="dialogDetail.visible"
    :width="600"
    :title="dialogDetail.title"
    draggable
    close-icon="CloseBold"
    @close="closeDialog(false)"
  >
    <el-descriptions v-loading="loading" :column="2">
      <el-descriptions-item label="项目名称">{{ detailInfo.projectName }}</el-descriptions-item>
      <el-descriptions-item label="锁定编号">{{ detailInfo.code }}</el-descriptions-item>
      <el-descriptions-item label="锁定月份">{{ detailInfo.lockMonth }}</el-descriptions-item>
      <el-descriptions-item label="锁定原因">{{ detailInfo.lockReason }}</el-descriptions-item>
      <el-descriptions-item label="锁定时间">{{ detailInfo.lockTime }}</el-descriptions-item>
      <el-descriptions-item label="申请人">{{ detailInfo.unlockApplicant }}</el-descriptions-item>
      <el-descriptions-item label="申请时间">{{ detailInfo.unlockApplicationTime }}</el-descriptions-item>
      <el-descriptions-item label="申请理由" :span="2">{{ detailInfo.unlockReason }}</el-descriptions-item>
      <el-descriptions-item label="申请附件" :span="2">
        <span
          v-for="item in detailInfo.attachments"
          :key="item.attachmentId"
          style="padding-right: 10px"
          @click="download(item.attachmentId)"
        >
          <el-link type="primary">{{ item.attachmentName }}</el-link>
        </span></el-descriptions-item
      >
      <el-descriptions-item v-if="detailInfo.auditStatus != 0" label="审核状态">
        <el-tag v-if="detailInfo.auditStatus == 1">{{ detailInfo.auditStatusName }}</el-tag>
        <el-tag v-if="detailInfo.auditStatus == 0" type="warning">{{ detailInfo.auditStatusName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item v-if="detailInfo.auditStatus != 0" label="审核结果">
        <el-tag v-if="detailInfo.auditIdea == 1" type="success">{{ detailInfo.auditIdeaName }}</el-tag>
        <el-tag v-else-if="detailInfo.auditIdea == -1" type="danger">{{ detailInfo.auditIdeaName }}</el-tag>
      </el-descriptions-item>
      <el-descriptions-item v-if="detailInfo.auditStatus != 0" label="审核意见">{{
        detailInfo.auditIdeaContent
      }}</el-descriptions-item>
      <el-descriptions-item v-if="detailInfo.auditStatus != 0" label="审核人">{{
        detailInfo.auditPerson
      }}</el-descriptions-item>
      <el-descriptions-item v-if="detailInfo.auditStatus != 0" label="审核时间">{{
        detailInfo.auditTime
      }}</el-descriptions-item>
      <el-descriptions-item label="执行状态">{{
        dialogDetail.dataInfo?.hasPush ? "已推送" : "未推送"
      }}</el-descriptions-item>
      <el-descriptions-item v-if="dialogDetail.dataInfo?.hasPush" label="推送时间">{{
        dialogDetail.dataInfo?.unlockTime
      }}</el-descriptions-item>
      <el-descriptions-item v-if="dialogDetail.dataInfo?.hasPush" label="推送结果">{{
        dialogDetail.dataInfo.unlockTime
      }}</el-descriptions-item>
      <el-descriptions-item v-if="dialogDetail.dataInfo?.hasPush" label="推送回复" :span="2">{{
        dialogDetail.dataInfo.unlockTime
      }}</el-descriptions-item>
      <el-descriptions-item v-if="dialogDetail.dataInfo?.hasPush" label="推送回复时间">{{
        dialogDetail.dataInfo.unlockTime
      }}</el-descriptions-item>
    </el-descriptions>
  </el-dialog>
</template>

<script lang="ts" setup>
import { GetProjectLockLog } from "@/api/admin/locklog/index";
import { downloadFile } from "@/utils";
import { downloadAttachment } from "@/api/common/other/index";

const props = defineProps({
  dialogDetail: {
    type: Object,
    default: () => ({
      visible: false,
      title: "开户审批",
      footBtn: "确认提交",
      id: 0,
      dataInfo: {},
    }),
  },
});

const { dialogDetail } = toRefs(props);

const emit = defineEmits(["sendClose"]);

const loading = ref(false);
const detailInfo = ref<any>({});

const download = (id: string) => {
  downloadAttachment(id).then((res) => {
    downloadFile(res);
  });
};

onMounted(() => {
  if (dialogDetail.value.visible) {
    loading.value = true;
    GetProjectLockLog(dialogDetail.value.id)
      .then((res) => {
        Object.assign(detailInfo.value, res.data);
      })
      .finally(() => {
        loading.value = false;
      });
  }
});

/**
 * 关闭弹窗
 */
function closeDialog(query: boolean) {
  emit("sendClose", query);
}
</script>

<style lang="scss" scoped>
.d_left {
  margin-left: 10px;
}
:deep(.el-form-item) {
  flex-wrap: wrap;
}

:deep(.el-input) {
  width: 80%;
}

:deep(.el-select) {
  width: 100%;
}

:deep(.el-input__wrapper) {
  width: 100%;
}

:deep(.el-form-item__label) {
  color: #696868;
  font-size: 13px;
}
</style>
